# This code will generate the x values by week_diff for figure 7
import pandas as pd
import statsmodels.formula.api as smf
from statsmodels.iolib.summary2 import summary_col

# read in file 'fig_7_x_pseudo_data.csv'' which should be in the same directory as this code
fig7 = pd.read_csv('fig_7_x_pseudo_data.csv')

# run regressions used for x values in figure 7
dfs = fig7
reg1 = smf.ols(formula="diff_ln_fee ~  C(week_diff) + moodys_first  + C(issuer_name)-1 ", data=dfs).fit(cov_type='cluster', cov_kwds={'groups': dfs[['week_diff']]})

# create table
results = summary_col([reg1],stars=True,float_format='%0.3f',
                  model_names=['1'],
                  info_dict={'N':lambda x: "{0:d}".format(int(x.nobs)),
                             'R2':lambda x: "{:.2f}".format(x.rsquared)},
                             regressor_order=[  'C(week_diff)[1.0]',
                                                'C(week_diff)[2.0]',
                                                'C(week_diff)[3.0]',
                                                'C(week_diff)[4.0]',
                                                'C(week_diff)[5.0]',
                                                'C(week_diff)[6.0]'],
                             drop_omitted=True)
# print table
print(results)
